import React, { useState } from 'react';
import {request} from 'dw-mx-request';
import {Button} from 'dw-mx';
import {ColFlex,FlexItem} from 'dw-mx-flex';

export default function PDFPrintDemo() {
    const [pdfData,setPdfData] = useState("");

    const printPageView = () => {
        const LODOP = getCLodop();
        LODOP.SET_LICENSES("山大地纬软件股份有限公司","CC9365E1BB34FA000175B357CD91F188454","山大地緯軟件股份有限公司","82F5D8E72ECF427F20ADD7E937E13D817E1");
        LODOP.SET_LICENSES("THIRD LICENSE","","Shanda DareWay Software Co., Ltd","1485033B74404D944BEA7FFAFB213175AF4");

        LODOP.PRINT_INIT("react使用打印插件CLodop");  //打印初始化
        LODOP.ADD_PRINT_PDF(0,0,'100%','100%',pdfData);
        LODOP.PREVIEW();  //最后一个打印(预览)语句

    };

    const onClick =async () => {
        const data = await request("/sef1/mx/test/testForWordPrinter")
        const iframe = document.getElementById('test');
        iframe.src = "data:application/pdf;base64,"+data;
        setPdfData(data);
    }

    return (
        <ColFlex>
            <FlexItem flexBasic={'90%'}>
                <iframe frameBorder={"0"} style={{height:'100%',width:'100%'}} id={"test"}></iframe>
            </FlexItem>
            <FlexItem>
                <Button type="primary" onClick={onClick} >预览</Button>
                <Button type="primary" onClick={printPageView} >打印</Button>
            </FlexItem>

        </ColFlex>
    )

}